package com.betterjr.modules.application.dubbo;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.betterjr.common.web.AjaxObject;
import com.betterjr.modules.application.IApplicationService;
import com.betterjr.modules.application.entity.Application;
import com.betterjr.modules.application.service.ApplicationService;
import com.betterjr.modules.rule.service.RuleServiceDubboFilterInvoker;

@Service(interfaceClass = IApplicationService.class)
public class ApplicationDubboService implements IApplicationService {

    @Autowired
    private ApplicationService applicationService;

    /**
     *  此方法用于查询前端根据 分组或者类型查询应用信息
    * @Title: webQueryEffectiveApplicationsByApplicationType 
     * @Description: 根据应用类型或者应用分类查询应用列表 ( 1 待发布 2 正常 3下架 4 已停用)
     * @param anApplcationTypeId  应用类型id
     * @param anApplcationGroupId  应用分组id
     * @return 
     * @see com.betterjr.modules.application.IApplicationService#webQueryEffectiveApplicationsByApplicationType(java.lang.Long, java.lang.Long) 
     * @author xuyp
     * @date 2017年11月15日 下午4:40:53
     */
    @Override
    public String webQueryEffectiveApplicationsByApplicationType(Long anApplcationTypeId, Long anApplcationGroupId,
            String anBusinStatus) {

        return AjaxObject.newOk("查询成功", applicationService
                .queryEffectiveApplicationsByApplicationType(anApplcationTypeId, anApplcationGroupId, anBusinStatus))
                .toJson();
    }

    /**
     * 平台admin查询应用表列表信息
     * <p>Overriding Method of webQueryApplicationsByMap</p>  
     * <p>Description: </p> 
     * @param anMap
     * @return 
     * @see com.betterjr.modules.application.IApplicationService#webQueryApplicationsByMap(java.util.Map) 
     * @author xuyp
     * @date 2017年12月12日 下午3:44:12
     * "applicationTypeId", "applicationGroupId", "ruleList",
                "applicationName", "businStatus"
     */
    @Override
    public String webQueryApplicationsByMap(Map<String, Object> anMap) {

        return AjaxObject.newOk("查询成功", applicationService.queryApplicationsByMap(anMap)).toJson();
    }

    /**
     * 
      * 新增或者保存应用信息
     * @Title: saveOrUpdateApplication 
     * @Description: 新增或者保存应用信息 
     * @param anApplication
     * @return 
     * @see com.betterjr.modules.application.IApplicationService#webSaveOrUpdateApplication(java.util.Map) 
     * @author xuyp
     * @date 2017年11月15日 下午4:41:38
     * 
     * id
     * applicationName
     * description
     * applicationIcon
     * applicationColor
     * applicationTypeId
     * applicationGroupId
     * ruleList
     * 
     * applicationShowType
     * showUrl
     */
    @Override
    public String webSaveOrUpdateApplication(Map<String, Object> anMap) {

        Application application = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("操作成功", applicationService.saveOrUpdateApplication(application)).toJson();
    }

    /**
     * 
     * <p>Overriding Method of webSaveModifyApplicationBusinStatus</p>  
     * <p>Description:更新应用的ｚｈｕａｎｇｔａｉ </p> 
     * @param anApplicationId  应用id
     * @param anBusinStatus 状态 应用状态 1 待发布  2 正常 3下架 4 已停用 9已删除
     * @return 
     * @see com.betterjr.modules.application.IApplicationService#webSaveModifyApplicationBusinStatus(java.lang.Long, java.lang.String) 
     * @author xuyp
     * @date 2017年11月22日 上午9:51:08
     */
    @Override
    public String webSaveModifyApplicationBusinStatus(Long anApplicationId, String anBusinStatus) {

        return AjaxObject
                .newOk("操作成功", applicationService.saveModifyApplicationBusinStatus(anApplicationId, anBusinStatus))
                .toJson();
    }

}
